<?php

namespace Api\Model;

use Think\Model;

class JobsInfoModel extends Model
{


    protected function _repetition_mobile($data)
    {
        $uid = M('Members')->where(array('mobile' => $data))->getfield('uid');
        if ($uid && $uid != $this->_user['uid']) return false;
        return true;
    }

    public function check_params()
    {
        $user_name = I('username', '');
        $sex = I('sex', 0);
        $birthdate = I('birthdate', 0);
        $first_work = I('first_work', 0);
        $hu_ji_di = I('hu_ji_di', '');
    }

    /**
     * 注销人才顾问添加操作记录
     * @param $user_info
     * @return bool
     */
    public static function out_gu_wen($user_info)
    {
        $res = M('members')->where(['uid' => $user_info['uid']])->setField('utype', 0);
        if ($res) {
            //添加注销记录
            M('gu_wen_log')->add([
                'uid' => $user_info['uid'],
                'type' => 1,
                'note' => '注销人才顾问',
                'level' => $user_info['level'],
                'level_name' => $user_info['level_name'],
                'add_time' => date('Y-m-d h:i:s', NOW_TIME),
            ]);
            return true;
        }
        return false;
    }

    protected function _parse($k, $str)
    {
        if ($str) {
            if (is_array($str)) {
                $arr = array_slice($str, 0, 20);
            } else {
                $arr = explode(',', $str);
                $arr = array_slice($arr, 0, 10);
            }
            foreach ($arr as $v) {
                $a = explode('.', $v);
                $t = range(0, 5);
                foreach ($t as $key => $val) {
                    $t[$key] = isset($a[$key]) ? intval($a[$key]) : 0;
                }
                for ($i = 5; $i >= 0; $i--) {
                    $d[] = $k . implode('_', $t);
                    unset($t[$i]);
                }
            }
            return $d ? '+(' . implode(' ', array_unique($d)) . ')' : false;
        }
        return false;
    }

    public function _where_jobcategory($data)
    {

        if ($data) {
            if (!strpos($data, ".")) {
                if (APP_SPELL && !fieldRegex($data, 'in')) {
                    $result = D('CategoryJobs')->jobs_cate_cache();
                    $arr = explode(",", $data);
                    foreach ($arr as $key => $val) {
                        $arr[$key] = $result['spell'][$val]['id'];
                    }
                } else {
                    if (fieldRegex($data, 'in')) {
                        $arr = explode(",", $data);
                    }
                }
                $arr = array_unique($arr);
                if ($arr) {
                    if (false === $jobs_cate = F('jobs_search_cate')) $jobs_cate = D('CategoryJobs')->jobs_search_cache();
                    foreach ($arr as $key => $val) {
                        $s[] = str_replace('_', '.', $jobs_cate[$val]);
                    }
                }
                return JobsInfoModel::_parse('jobs', $s);
            } else {
                return JobsInfoModel::_parse('jobs', $data);
            }
        } else {
            $topclass = $category = $subclass = array();
            if (trim($this->params['topclass'])) {
                if (fieldRegex($this->params['topclass'], 'in')) {
                    $arr = explode(",", $this->params['topclass']);
                    $topclass = array_slice($arr, 0, 20);
                }
            }
            if (trim($this->params['category'])) {
                if (fieldRegex($this->params['category'], 'in')) {
                    $arr = explode(",", $this->params['category']);
                    $category = array_slice($arr, 0, 20);
                }
            }
            if (trim($this->params['subclass'])) {
                if (fieldRegex($this->params['subclass'], 'in')) {
                    $arr = explode(",", $this->params['subclass']);
                    $subclass = array_slice($arr, 0, 20);
                }
            }
            if ($d = array_merge($topclass, $category, $subclass)) {
                $d = array_unique($d);
                if (false === $jobs_cate = F('jobs_search_cate')) $jobs_cate = D('CategoryJobs')->jobs_search_cache();
                foreach ($d as $key => $val) {
                    $s[] = 'jobs' . $jobs_cate[$val];
                }
            }
            return $s ? '+(' . implode(' ', array_unique($s)) . ')' : false;
        }
    }

    /**
     * 获取我的人才
     * @param $uid
     * @param int $page
     * @param int $page_size
     * @param int $cate_id
     * @return mixed
     */
    public function get_rencai($uid, $page = 1, $page_size = 10, $cate_id = 0, $key = '')
    {
        $where['g.guwen_id'] = $uid;// = 1;
        $where['g.status'] = 0;
        if ($key) {
            $where['m.username'] = ['like', "%$key%"];
        }
        if ($cate_id) {

            $res = JobsInfoModel::_where_jobcategory($cate_id);
            //   var_dump($res);die;
            $where["key_full"] = ['match_mode', ['+trade11']];
        }
        $res = M('guwen_user')->field('g.uid,g.id')->join('as g left join qs_members as m on g.uid=m.uid')
            ->join('left join qs_resume as r on r.uid=g.uid')
            ->where($where)->page($page, $page_size)->select();
        // var_dump(M('guwen_user')->getLastSql());DIE;
        foreach ($res as $k => $v) {
            $jian_info = M('resume')->field('trade_cn,current_cn,fullname,first_work_date,intention_jobs,major_cn')->where(['uid' => $v['uid']])->find();
            $user_info = M('members')->where(['uid' => $v['uid']])->find();
         //   var_dump($jian_info);die;
            if($jian_info['first_work_date']){
                $times=diffDate(date('Y-m-d'),$jian_info['first_work_date']);
              //  if($times['year']>0){
                    $res[$k]['experience_cn']=$times['year'].'年';
//                }else{
//                    $res[$k]['experience_cn']=$times['month'].'月'.$times['day'].'天';
//                }
            }else{
                $res[$k]['experience_cn']='暂无';
            }
            $res[$k]['username'] = $jian_info['fullname']?$jian_info['fullname']:$user_info['username'];
            $res[$k]['avatars'] = avatar($user_info);
            $res[$k]['intention_jobs'] = $jian_info['intention_jobs'];
            $res[$k]['major_cn'] = $jian_info['trade_cn'];
            $res[$k]['current_cn'] = $jian_info['current_cn'];
            //$res[$k]['experience_cn'] = $jian_info['experience_cn'];
           $count = M('order')->join('as o right join qs_company_down_resume as c on o.rid=c.resume_id')
                 ->where(['c.resume_uid' => $v['uid'],'o.order_type'=>'14'])->count();

          // var_dump( M('order')->getLastSql());//die;
        //   $count=M('company_down_resume')->where([''])->count();
            $res[$k]['count'] = $count;
            $money = M('order')->join('as o left join qs_company_down_resume as c on o.rid=c.resume_id')
                ->where(['c.resume_uid' => $v['uid'],'o.order_type'=>'14'])->sum('o.pay_amount');
            $res[$k]['money'] = $money ? $money : 0;
            $res[$k]['sex'] = M('resume')->where(['uid' => $v['uid']])->getField('sex');
            $res[$k]['reg_time'] = date('Y-m-d');
            $time = M('order')->join('as o left join qs_company_down_resume as c on o.uid=c.company_uid')
                ->where(['c.resume_id' => $uid])->order('id desc')->find();//更新时间
            $res[$k]['up_time'] = $time ? date('Y-m-d', $time['down_addtime']) : $res[$k]['reg_time'];
        }
        return $res;
    }

    /**
     * 简历列表
     * @return mixed
     */

    public static function get_resume_list()
    {
        $tag_resume_list_class = new \Common\qscmstag\resume_listTag(array('接口' => '1','用户名'=>_I(I('fullname')),'居住地分类'=>_I(I('residence')),'求职状态'=>_I(I('current')),'语言'=>_I(I('language')),'语言等级'=>_I(I('language_level')),'到岗时间'=>_I(I('dao_gang')), '列表名' => 'resumelist', '搜索类型' => _I(I('search_type')), '显示数目' => '15', '分页显示' => _I(I('page', 1)), '关键字' => _I(I('key')), '职位分类' => _I(I('jobcategory')), '地区分类' => _I(I('citycategory')), '日期范围' => _I(I('settr')), '学历' => _I(I('education')), '工作经验' => _I(I('experience')), '工资' => _I(I('wage')), '工作性质' => _I(I('nature')), '标签' => _I(I('resumetag')), '照片' => _I(I('photo')), '所学专业' => _I(I('major')), '行业' => _I(I('trade')), '年龄' => _I(I('age')), '性别' => _I(I('sex')), '特长描述长度' => '100', '排序' => _I(I('sort')), '检测登录' => '1', 'cache' => '0', 'type' => 'run',));
        $resumelist = $tag_resume_list_class->run();
        $list['list'] = $resumelist['list'];
        $list['total'] = $resumelist['total'];
        return $list;
    }

    /**
     * 简历详情
     * @return mixed
     */

    public static function resume_detail()
    {
        $tag_resume_show_class = new \Common\qscmstag\resume_showTag(array('列表名' => 'info', '简历id' => _I(I('id')), 'cache' => '0', 'type' => 'run',));
        $info = $tag_resume_show_class->run();
        return $info;
    }

    /**
     * 获取工程币套餐列表
     * @return mixed
     */

    public static function get_gcb_list()
    {
        $list = M('setgcb')->where(['display' => 1])->order('id desc')->select();
        foreach ($list as $k=>$v){
            if($v['price_rate']>0){
                $list[$k]['price']=number_format($v['price']*$v['price_rate']/100,2);
            }
        }
        return $list;
    }

    /**
     * 获取套餐列表
     * @return mixed
     */

    public static function get_taocan_list()
    {
        $list = M('settaocan')->where(['display' => 1])->order('id desc')->select();
        foreach ($list as $k=>$v){
            if($v['price_rate']>0){
                $list[$k]['expense']=number_format($v['expense']*$v['price_rate']/100,2);
            }
        }
        return $list;
    }

    /**
     * 获取简历数量
     * @return mixed
     */
    public static function get_res_count()
    {
        $where['company_uid'] = C('visitor.uid');
        $db_pre = C('DB_PREFIX');
        $join = 'as c right join ' . $db_pre . 'resume r on r.id=c.resume_id';
        $all_count = D('PersonalJobsApply')->where($where)->count();  //所有
        $weikan_count = D('PersonalJobsApply')->join($join)->where(['c.is_del' => 0,'company_uid'=> C('visitor.uid')])->where(['personal_look' => 1])->count(); //未读
     //  var_dump(D('PersonalJobsApply')->getLastSql());die;

        $this_t = $db_pre . 'company_down_resume';
       // $join = 'as c right join ' . $db_pre . 'resume r on r.id=c.resume_id';
        $res_down_count = D('CompanyDownResume')->where($where)->where(['c.is_del' => 0])->join($join)->count();  //下载
        $guwen_tui_count = 0;//顾问推荐

        $where_tui['gj.fa_type']=4;
        $where_tui['gj.comp_uid']=C('visitor.uid');
        if(I('jobs_id')){
            $where_tui['gj.jobs_id']=I('jobs_id');
        }
        $uids=M('gu_wen_jie_dan_order')->join('as gj left join qs_guwen_tui_jian_rusume as gt on gj.id=gt.order_id')->where($where_tui)->getField('gt.id,gt.resume_uid',true);
       if($uids){
           $guwen_tui_count=M('resume')->join('as r left join qs_members as m on r.uid=m.uid')
               ->field('r.sex,m.avatars,r.fullname,m.username,m.uid,r.trade_cn,intention_jobs,r.current_cn,r.refreshtime,r.experience_cn')
               ->where(['r.uid'=>['in',$uids]])->count();
       }

        $db_pre = C('DB_PREFIX');
        $this_t = $db_pre . 'company_favorites';
        $join = 'as c right join ' . $db_pre . 'resume r on r.id=c.resume_id';
        $sc_count = D('CompanyFavorites')->where($where)->where(['c.is_del' => 0])->join($join)->count();  //收藏
        $del_count = M('company_resume_del')->where($where)->count();   //删除
        $data['all_count'] = $all_count;
        $data['weikan_count'] = $weikan_count;
        $data['res_down_count'] = $res_down_count;
        $data['guwen_tui_count'] = $guwen_tui_count;
        $data['sc_count'] = $sc_count;
        $data['del_count'] = $del_count;

        return $data;
    }

    /**
     * 获取用户的套餐的使用记录
     * @param $where
     * @param $page
     * @param $page_size
     * @return mixed
     */
    public static function get_member_use_log($where, $page, $page_size)
    {
        $list = M('member_use_log')->field('add_time as addtime,price as pay_amount,`desc` as description')->where($where)->page($page, $page_size)->order('id desc')->select();

        $count=M('member_use_log')->where($where)->count();
        return ['list'=>$list,'total'=>$count];
    }

    /**
     * 获取微信支付的记录
     * @param $where
     * @param $page
     * @param $page_size
     */

    public static function get_wxpay_log($where, $page, $page_size)
    {
        $where['use_type'] = 'wxpay';
        $list = M('member_use_log')->where($where)->page($page, $page_size)->select();
        return $list;
    }

    /**
     * 验证职位发布提交的参数
     * @return array
     */
    public static function check_fabu_params()
    {
        $zhao_type = I('zhao_type', 0);
        if (in_array($zhao_type, [3, 4])) {
            $project_name = I('project_name', '');
            $project_desc = I('project_desc', '');
            if (empty($project_name) || empty($project_desc)) {
                return ['status' => 1, 'msg' => '请填写项目信息'];
            }

            $xm_day = I('xm_day', 0);
            if (empty($xm_day)) {
                return ['status' => 1, 'msg' => '请填写项目工期'];
            }
            if ($zhao_type == 4) {
                //项目专场

            } elseif ($zhao_type == 3) {
                //短期
                $duan_qi_money = I('duan_qi_money', 0);
                if (empty($duan_qi_money)) {
                    return ['status' => 1, 'msg' => '请填写薪资具体数额'];
                }
                if($xm_day>=90){
                    return ['status' => 1, 'msg' => '短期职位项目周期不能大于90天'];
                }
//                $money_info=M('config')->where(['name'=>['in',['one_month','two_month','three_month']]])->select();
//                $data=[];
//                foreach ($money_info as $k=>$v){
//                    $data[$v['name']]=$v['value'];
//                }
//                if($xm_day<30 && $duan_qi_money<$data['one_month']){
//                    return  ['status'=>1,'msg'=>'金额不能低于'.$data['one_month']];
//                }
//                if($xm_day<60 && $duan_qi_money<$data['two_month']){
//                    return  ['status'=>1,'msg'=>'金额不能低于'.$data['two_month']];
//                }
//                if($xm_day<90 && $duan_qi_money<$data['three_month']){
//                    return  ['status'=>1,'msg'=>'金额不能低于'.$data['three_month']];
//                }
            }
            $gw_city_ids = I('gw_city_ids', 0);
//            if (empty($gw_city_ids)) {
//                return ['status' => 1, 'msg' => '请选择岗位地址'];
//            }
            $work_time_id = I('work_time_id', 0);
            if (empty($work_time_id)) {
                return ['status' => 1, 'msg' => '请选择工作时间'];
            }
            $zi_ding_yi_work_time = I('zi_ding_work_time', '');
            $xiu_jia = I('xiu_jia', 0);
//            if (empty($xiu_jia)) {
//                return ['status' =>1, 'msg' => '请填写休假制度'];
//            }
        }
        $job_name = I('job_name', '');
        if (empty($job_name)) {
            return ['status' => 1, 'msg' => '请填写职位名称'];
        }
        $_job_cate_id = I('job_cate_id', 0);
        if (empty($_job_cate_id)) {
            return ['status' => 1, 'msg' => '请选择职位分类'];
        }
        $cate_info = explode(',', $_job_cate_id);
        foreach ($cate_info as $k => $v) {
            $arr = explode('-', $v);
            $job_cate_id[$k] = $arr[1];
            $topclass[$k] = $arr[0];
        }
        //var_dump($job_cate_id);die;
        $trade_id = I('trade_id', 0);
        if (empty($trade_id)) {
            return ['status' => 1, 'msg' => '请选择工程类别'];
        }
        $trade_info = explode(',', $trade_id);
        //由于前端不改  格式不对   需要解析一下
        foreach ($trade_info as $k => $v) {
            $trade__p_info = explode('-', $v);
            $arr_a[] = $trade__p_info[1];
            $top_trade[]=$trade__p_info[0];
            //  var_dump($arr);
        }
        $trade_id = implode(',', $arr_a);
        $top_trade_id = implode(',', $top_trade);
        $city_id = I('city_id', 0);
        if (empty($city_id)) {
            return ['status' => 1, 'msg' => '请选择工作或项目地址'];
        }
        $addres_detail = I('addres_detail', '');
         if($zhao_type!=3 && $zhao_type!=4){
             if (empty($addres_detail)) {
                 return ['status' => 1, 'msg' => '请输入详细地址'];
             }
         }
        $fa_bu_ids = I('fa_bu_ids', 0);
        if (empty($fa_bu_ids)) {
            return ['status' => 1, 'msg' => '请选择发布城市'];
        }
        $experience_id = I('experience_id', 0);
//        if(empty($experience_id)){
//            return ['status'=>1,'msg'=>'请选择工作经验'];
//        }
        $wage_id = I('wage_id', 0);
        if($zhao_type != 3){
            if (empty($wage_id)) {
                return ['status' => 1, 'msg' => '请选择薪资范围'];
            }
        }

        $language_id = I('language_id', 0);
//        if (empty($language_id)) {
//            return ['status' => 1, 'msg' => '请选择语言种类'];
//        }

        $language_lev_id = I('language_lev_id', 0);

//        if (empty($language_lev_id)) {
//            return ['status' => 1, 'msg' => '请选择语言要求熟练度'];
//        }
        $education_id = I('education_id', 0);
//        if(empty($education_id)){
//            return ['status'=>1,'msg'=>'请选择学历要求'];
//        }
        $nature_id = I('nature_id', 0);
        if (empty($nature_id)) {
            return ['status' => 1, 'mag' => '请选择工作性质'];
        }
        $dao_gang_time = I('dao_gang_id', 0);
//        if (empty($dao_gang_time)) {
//            return ['status' => 1, 'msg' => '请选择到岗时间'];
//        }
        $zhi_ding_time = I('zhi_ding_time', '');
        if ( $dao_gang_time==316 && empty($zhi_ding_time)) {
            return ['status' => 1, 'msg' => '请选择指定到岗时间'];
        }
        $zi_dy_fl = I('zi_dy_fl', '');//自定义福利

        $jobtag_id = I('jobtag_id', 0);//1,2,4
//        if (empty($jobtag_id)) {
//            return ['status' => 1, 'msg' => '请选择福利条件'];
//        }
        $amount = I('amount', 0);
        if (empty($amount)) {
            return ['status' => 1, 'msg' => '请填写招聘人数'];
        }

        $gw_zhi_ze = I('gw_zhi_ze', '');
        if (empty($gw_zhi_ze)) {
            return ['status' => 1, 'msg' => '请填写岗位职责'];
        }
        $gw_yao_qiu = I('gw_yao_qiu', '');
        if (empty($gw_yao_qiu)) {
            return ['status' => 1, 'msg' => '请填写岗位要求'];
        }

        $zhao_end_time = I('zhao_end_time', '');
//        if (empty($zhao_end_time)) {
//            return ['status' => 1, 'msg' => '请选择结束日期'];
//        }
        if($zhao_end_time){
            $zhao_end_time_time = strtotime($zhao_end_time);
            if (time() > $zhao_end_time_time) {
                return ['status' => 1, 'msg' => '职位结束日期不能小于当前时间'];
            }
        }
        $js_email = I('email', '', 'trim,badword');
//        if (empty($js_email)) {
//            return ['status' => 1, 'msg' => '请填写结束简历邮箱'];
//        }
//        if (!fieldRegex($js_email, 'email')) {
//            return ['status' => 1, 'msg' => '邮箱格式错误，请重新输入'];
//        }
        $department = I('department', '');
//        if (empty($department)) {
//            return ['status' => 1, 'msg' => '请填写职位部门'];
//        }
        $ziding_yi_tags = I('ziding_yi_tags', '');//自定义福利标签
        $data['map_x']=I('map_x',0);
        $data['map_y']=I('map_y',0);
        $data['top_trade']=$top_trade_id;
        $data['topclass'] = $topclass;
        $data['department'] = $department;
        $data['ziding_yi_tags'] = $ziding_yi_tags;
        $data['js_email'] = $js_email;
        $data['zhao_end_time'] = $zhao_end_time;
        $data['gw_yao_qiu'] = $gw_yao_qiu;
        $data['amount'] = $amount;
        $data['tag'] = $jobtag_id;
        $data['zhi_ding_time'] = $zhi_ding_time;
        $data['dao_gang_id'] = $dao_gang_time;
        $data['nature'] = $nature_id;
        $data['jobs_name'] = $job_name;
        $data['companyname'] = '';
        $data['company_id'] = 1;
        $data['uid'] = 1;
        $data['company_addtime'] = time();
        $data['sex'] = 3;
        $data['category'] = $job_cate_id;
        $data['trade'] = $trade_id;
        $data['district'] = $city_id;
        $data['education'] = $education_id;
        $data['experience'] = $experience_id;
        $data['contents'] = $gw_zhi_ze;
        $data['language_lev_id'] = $language_lev_id;
        $data['language_id'] = $language_id;
        $data['wage_id'] = $wage_id;
        $data['project_name'] = $project_name;
        $data['project_desc'] = $project_desc;
        $data['addres_detail'] = $addres_detail;
        $data['fa_bu_ids'] = $fa_bu_ids;
        $data['zhao_type_id'] = $zhao_type;
        $data['refreshtime'] = time();
        $data['stime'] = time();
        $data['zi_dy_fl'] = $zi_dy_fl;
        $data['xm_day'] = $xm_day;
        $data['duan_qi_money']=$duan_qi_money;
        $data['xiu_jia']=$xiu_jia;
        $data['work_time_id']=$work_time_id;
        $data['zi_ding_work_time']=$zi_ding_yi_work_time;
        $data['old_zhao_type_id']=$data['zhao_type_id'];
      //  var_dump($data);die;
        return ['status' => 0, 'msg' => '', 'data' => $data];
    }


    /**
     * 顾问推荐人才
     * @param $order_id string 接单订单id
     * @param $jobs_id string 职位id
     * @param $uids_arr array 用户id
     * @param $desc  string 评语
     * @param $jobs_info array  职位数据
     * @param int $desc_id 描述id
     * @param string $server_money   保证金
     * @param string $xishu_rate 系数
     * @return array
     */
    public static function guwen_tui_jian($order_id, $jobs_id, $uids_arr, $desc, $jobs_info, $desc_id = 0,$server_money=0,$xishu_rate=0)
    {
        //判断是否呗推荐过
        $res = M('guwen_tui_jian_rusume')->field('r.fullname')
            ->join('as gr right join  qs_resume as r on gr.resume_uid=r.uid')
            ->where(['gr.jobs_id' => $jobs_id, 'resume_uid' => ['in', $uids_arr]])->select();
        if ($res) {
            $user_name = '';
            foreach ($res as $k => $v) {
                $user_name .= $v['fullname'] . ',';
            }
            $user_name = substr($user_name, 0, strlen($user_name) - 1);
            return ['status' => 1, 'msg' => '【' . $user_name . '】已被推荐，请重新选择'];
        }
        foreach ($uids_arr as $k => $v){
           $jian_info=M('resume')->where(['uid'=>$v])->find();
           if(empty($jian_info)){
               return  ['status'=>1,'msg'=>'请选择简历完善了的人才'];
           }
        }
        $order_info=M('gu_wen_jie_dan_order')->where(['id'=>$order_id,'gw_uid'=>C('visitor.uid')])->find();
        $sess = S('jie_dan_time'.$jobs_id);
        if ($sess) {
            $start_time = $sess['time'];
            $end_time = strtotime("+72 hours", $start_time);
            $count = M('guwen_tui_jian_rusume')->where(['jobs_id' => $jobs_id, 'order_id' => $order_id, 'guwen_uid' => C('visitor.uid'), 'add_time' => ['between', "$start_time,$end_time"]])->count();
            //判断当前时间内是否推送了3个
            if ($count >= 3 || $count + count($uids_arr) > 3) {
                return ['status' => 1, 'msg' => '72小时内最多推送三个'];
            }
            foreach ($uids_arr as $k => $v) {
                $oid = "L-" . date('ymd', time()) . "-" . date('His', time()); //订单号
                M('guwen_tui_jian_rusume')->add([
                    'guwen_uid' => C('visitor.uid'),
                    'resume_uid' => $v,//用户id
                    'jobs_id' => $jobs_id,//职位id
                    'order_id' => $order_id,//订单id
                    'add_time' => time(),
                    'desc' => $desc,
                    'desc_id' => $desc_id,
                    'comp_uid' => $jobs_info['uid'],//企业id
                    'tui_status' => 0,//录用状态  0 未处理 1 录用 2未录用
                    'server_money'=>$server_money,
                    'xishu_rate'=>$xishu_rate,
                    'oid'=>$oid,
                ]);
            }
            if(!in_array($order_info['order_status'],[2,3])){
                M('gu_wen_jie_dan_order')->where(['id'=>$order_id,'gw_uid'=>C('visitor.uid')])->setField('order_status',6);
            }
            //判断企业之前是否下载的推荐用户的简历
            //如果下载了  则 修改订单状态
            $count=M('company_down_resume')->where(['company_uid'=>$jobs_info['uid'],'resume_uid'=>['in',$uids_arr]])->getField('resume_uid',true);
            if($count){
                M('gu_wen_jie_dan_order')->where(['id'=>$order_id,'gw_uid'=>C('visitor.uid')])->setField('order_status',2);
            }

            return ['status' => 0, 'msg' => '推荐成功'];
        } else {
            $data['time'] = time();
            $data['jobs_id'] = $jobs_id;
            $data['uid'] = C('visitor.uid');
            S('jie_dan_time'.$jobs_id, $data, ['expire' => 86400 * 3]);
            foreach ($uids_arr as $k => $v) {
                $oid = "L-" . date('ymd', time()) . "-" . date('His', time()); //订单号
                M('guwen_tui_jian_rusume')->add([
                    'guwen_uid' => C('visitor.uid'),
                    'resume_uid' => $v,//用户id
                    'jobs_id' => $jobs_id,//职位id
                    'order_id' => $order_id,//订单id
                    'add_time' => time(),
                    'desc' => $desc,
                    'desc_id' => $desc_id,
                    'comp_uid' => $jobs_info['uid'],//企业id
                    'tui_status' => 0,//录用状态  0 未处理 1 录用 2未录用
                    'server_money'=>$server_money,
                    'xishu_rate'=>$xishu_rate,
                    'oid'=>$oid,
                ]);
            }
            if(!in_array($order_info['order_status'],[2,3])){
                M('gu_wen_jie_dan_order')->where(['id'=>$order_id,'gw_uid'=>C('visitor.uid')])->setField('order_status',6);
             }
            //判断企业之前是否下载的推荐用户的简历
            //如果下载了  则 修改订单状态
            $count=M('company_down_resume')->where(['company_uid'=>$jobs_info['uid'],'resume_uid'=>['in',$uids_arr]])->getField('resume_uid',true);
            if($count){
                M('gu_wen_jie_dan_order')->where(['id'=>$order_id,'gw_uid'=>C('visitor.uid')])->setField('order_status',2);
            }
           // M('gu_wen_jie_dan_order')->where(['id'=>$order_id,'gw_uid'=>C('visitor.uid')])->setField('order_status',6);
            return ['status' => 0, 'msg' => '推荐成功'];
        }
    }

    /**
     * 添加用户的支付记录
     * @param $uid
     * @param $order_id
     * @param $oid
     * @param $price
     * @param $pay_type
     * @param $desc
     * @param $pay_time
     * @param $order_type
     * @return mixed
     */

    public static function add_user_pay_log($uid,$order_id,$oid,$price,$pay_type,$desc,$pay_time,$order_type)
    {
     $res=   M('user_pay_log')->add([
           'uid'=>$uid,
            'order_id'=>$order_id,
            'oid'=>$oid,
            'price'=>$price,
            'pay_time'=>$pay_time,
            'desc'=>$desc,
            'pay_type'=>$pay_type,
            'order_type'=>$order_type
        ]);
       return $res;
    }
}

?>